﻿<?php
function DoCommandSysConfig($command_type)
{
	switch ($command_type) {
		case "edit_user_first_login":
			HttpAction_EditUserFirstLogin();	//修改用户登录提示信息
			break;
		case "select_user_first_login":
			HttpAction_SelectUserFirstLogin();	 //查询用户首次登陆设置信息
			break;		
			
		case "edit_config_level":
			HttpAction_EditConfigLevel();		//修改某逻辑配置
			break;
		case "delete_config_level":
			HttpAction_DeleteConfigLevel();		//删除某逻辑配置
			break;
		case "select_config_level":
			HttpAction_SelectConfigLevel();		//查询某条逻辑信息
			break;			
			
		case "edit_config_logic":
			HttpAction_EditConfigLogic();		//修改某逻辑配置
			break;
		case "delete_config_logic":
			HttpAction_DeleteConfigLogic();		//删除某逻辑配置
			break;
		case "select_config_logic":
			HttpAction_SelectConfigLogic();		//查询某条逻辑信息
			break; 
			
		case "send_sys_info":
			HttpAction_SendSysInfo();			//发送系统消息
			break; 
		
		case "edit_Config_sys_info_homepage_msg":
			HttpAction_EditConfigSysInfoHomePageMsg();	//修改首页滚动信息
			break;
		case "select_Config_sys_info_homepage_msg":
			HttpAction_SelectConfigSysInfoHomePageMsg();	 //查询首页滚动信息
			break;
			
		case "select_Config_sys_register_sex_left_info":
			HttpAction_SelectConfigSysRegisterSexLeftInfo();	 //查询注册-左边滚动信息设置
			break;
		case "edit_Config_sys_register_sex_left_info":
			HttpAction_EditConfigSysRegisterSexLeftInfo();		//修改注册-左边滚动信息设置
			break;
		
			
		default:
			break;
	}
}
 
function DoCommandPagindSysConfig($command_type)
{
	switch ($command_type) {
		case "get_config_level_total": 	//等级配置--总数
			HttpAction_GetConfigLevelTotal();
			break;
		case "get_config_level_list":	//等级配置--列表
			HttpAction_GetConfigLevelList();
			break;
			
		case "get_config_logic_total": 	//逻辑配置--总数
			HttpAction_GetConfigLogicTotal();
			break;
		case "get_config_logic_list":	//逻辑配置--列表
			HttpAction_GetConfigLogicList();
			break;
		default:
			break;
	}
} 
 
//-------系统配置修改---1------------
//--用户登录提示
function HttpAction_EditUserFirstLogin()
{ 
	$prompt_value = GetRequest("user_first_login");
	$str_sql = sprintf("select * from t_config_logic where name = 'Config_user_first_login_info';"); 
	
	$bExec = true;
	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == - 1) 
	{
		PrintMsgToHTML("错误：" . $msg);
		return;
	}

	if (count($rsArray) > 0) 
	{	//存在，则修改 
		$str_sql = sprintf("update t_config_logic set  remark = '%s'  where name = 'Config_user_first_login_info';",
		EscapeString($prompt_value));
	} 
	else 
	{
		$str_sql = sprintf("insert into t_config_logic(name, remark) values('Config_user_first_login_info', '%s');",
		EscapeString($prompt_value));
	} 	
	DBHelper::ExecReturnJSON($str_sql);
    //DBHelper::ExecAndPrintMsg($str_sql);
}

//查询用户首次登陆信息
function HttpAction_SelectUserFirstLogin() 
{		 
	$str_sql = "select remark from t_config_logic where name = 'Config_user_first_login_info';"; 
	DBHelper::QueryReturnJSON($str_sql);
}

//发送系统消息
function HttpAction_SendSysInfo()
{ 
	$sys_info_content = GetRequest("sys_info_content");
	$str = sprintf('sys_info {"type":"send", "content":"%s"}', $sys_info_content);
	socketDataExt($str); //----通知服务端
	ReturnJSONMsg("发送成功");
}		
 
//-------系统配置修改--2-------------
//配置--等级总数
function HttpAction_GetConfigLevelTotal()
{	
	$str_sql = sprintf("select count(*) as total_count from t_config_level");
	DBHelper::QueryReturnJSON($str_sql);
}

//配置--等级列表
function HttpAction_GetConfigLevelList()
{
	$page_index = GetRequest("page_index"); //当前查询的页码
	$per_page_count = GetRequest("per_page_count"); //每页行数
	$count = ($page_index - 1) * $per_page_count;

	$str_sql = sprintf("select * from t_config_level ");
	$str_sql = sprintf("%s limit %d, %d", $str_sql, $count, $per_page_count);

	DBHelper::QueryReturnJSON($str_sql);
}

//修改某逻辑配置
function HttpAction_EditConfigLevel()		
{
	$level = GetRequest("level"); 
	$exp = GetRequest("exp"); 
	$courage = GetRequest("courage"); 
	$power = GetRequest("power"); 
	
	$energy = GetRequest("energy"); 
	$quality = GetRequest("quality"); 
	$remark = GetRequest("remark");  
	$gift_goods_list = GetRequest("gift_goods_list");  
		
	$str_sql = sprintf("select level from t_config_level where level = '%s'", $level); 
	
	$bExec = true;
	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == - 1) 
	{
		PrintMsgToHTML("错误：" . $msg);
		return;
	}

	if (count($rsArray) > 0) 
	{	//存在，则修改
		$str_sql = sprintf("update t_config_level set exp='%s', courage='%s', power='%s', energy='%s', quality='%s', 
			remark='%s', gift_goods_list='%s'   where level='%s';",  
			EscapeString($exp), 
			EscapeString($courage), 
			EscapeString($power), 
			EscapeString($energy), 
			EscapeString($quality), 
			EscapeString($remark),
			EscapeString($gift_goods_list),
			EscapeString($level)
		); 
	} 
	else 
	{
		//不存在, 则新增
		$str_sql = sprintf("insert into t_config_level(level, exp, courage, power, energy, quality, remark, gift_goods_list) 
			values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",   
			EscapeString($level), 
			EscapeString($exp), 
			EscapeString($courage), 
			EscapeString($power), 
			EscapeString($energy), 
			EscapeString($quality), 
			EscapeString($remark), 
			EscapeString($gift_goods_list)
		); 
	}
	 
	DBHelper::ExecReturnJSON($str_sql); 
}
//删除某逻辑配置
function HttpAction_DeleteConfigLevel()		
{
	$level = GetRequest("level"); 
		 
	$str_sql = sprintf("delete from t_config_level where level = %s", $level);  
	DBHelper::ExecReturnJSON($str_sql);
}
//查询某条逻辑信息
function HttpAction_SelectConfigLevel() 
{
	$level = GetRequest("level"); 
		 
	$str_sql = sprintf("select * from t_config_level where level = %s", $level);  
	DBHelper::QueryReturnJSON($str_sql);
}


 
//配置--等级总数
function HttpAction_GetConfigLogicTotal()
{	
	$str_sql = sprintf("select count(*) as total_count from t_config_logic");
	DBHelper::QueryReturnJSON($str_sql);
}

//配置--等级列表
function HttpAction_GetConfigLogicList()
{
	$page_index = GetRequest("page_index"); //当前查询的页码
	$per_page_count = GetRequest("per_page_count"); //每页行数
	$count = ($page_index - 1) * $per_page_count;

	$str_sql = sprintf("select * from t_config_logic ");
	$str_sql = sprintf("%s limit %d, %d", $str_sql, $count, $per_page_count);

	DBHelper::QueryReturnJSON($str_sql);
}

//修改某逻辑配置
function HttpAction_EditConfigLogic()		
{	
	$name = GetRequest("name");			//    
	$alias = GetRequest("alias");		//别名  
	$module = GetRequest("module");		//模块名  
	$gold = GetRequest("gold");			//金币
	$money = GetRequest("money");			//金币
	$exp = GetRequest("exp");			//经验值
	$charm = GetRequest("charm");		//魅力增减
	$courage = GetRequest("courage");	//勇气值 
	$power = GetRequest("power");	//勇气值 	
	$energy = GetRequest("energy");		//精力(人缘)(关注人数) 
	$quality = GetRequest("quality"); 	//人品值 
	$other = GetRequest("other"); 		//其它 
	$remark = GetRequest("remark"); 	//备注 
		
	$str_sql = sprintf("select name from t_config_logic where name = '%s'", $name); 
	
	$bExec = true;
	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == - 1) 
	{
		PrintMsgToHTML("错误：" . $msg);
		return;
	}

	if (count($rsArray) > 0) 
	{	//存在，则修改
		$str_sql = sprintf("update t_config_logic set  alias='%s', module='%s', gold='%s', money='%s', exp='%s', charm='%s', courage='%s',power='%s',
			 energy='%s', quality='%s', other='%s',  remark='%s'   where name='%s';",  
			EscapeString($alias), 
			EscapeString($module), 
			EscapeString($gold), 
			EscapeString($money), 
			EscapeString($exp), 
			EscapeString($charm), 
			EscapeString($courage),  
			EscapeString($power),  
			EscapeString($energy), 
			EscapeString($quality), 
			EscapeString($other),
			EscapeString($remark),
			EscapeString($name)
		); 
	} 
	else 
	{
		//不存在, 则新增
		$str_sql = sprintf("insert into t_config_logic(name, alias, module, gold, money, exp, charm, courage,power, energy, quality, other, remark) 
			values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", 
			EscapeString($name),  
			EscapeString($alias), 
			EscapeString($module), 
			EscapeString($gold), 
			EscapeString($money), 
			EscapeString($exp), 
			EscapeString($charm), 
			EscapeString($courage),  
			EscapeString($power),  
			EscapeString($energy), 
			EscapeString($quality), 
			EscapeString($other),
			EscapeString($remark)
		); 
	}	
	DBHelper::ExecReturnJSON($str_sql); 
}
//删除某逻辑配置
function HttpAction_DeleteConfigLogic()		
{
	$name = GetRequest("name"); 
		 
	$str_sql = sprintf("delete from t_config_logic where name = '%s'", $name); 
	DBHelper::ExecReturnJSON($str_sql);
}
//查询某条逻辑信息
function HttpAction_SelectConfigLogic() 
{
	$name = GetRequest("name"); 
		 
	$str_sql = sprintf("select * from t_config_logic where name = '%s'", $name);  
	DBHelper::QueryReturnJSON($str_sql);
} 


//----------------------首页滚动信息--------------------
function HttpAction_EditConfigSysInfoHomePageMsg()
{ 
	$prompt_value = GetRequest("Config_sys_info_homepage_msg");
	$str_sql = sprintf("select * from t_config_logic where name = 'Config_sys_info_homepage_msg';"); 
	
	$bExec = true;
	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == - 1) 
	{
		PrintMsgToHTML("错误：" . $msg);
		return;
	}

	if (count($rsArray) > 0) 
	{	//存在，则修改 
		$str_sql = sprintf("update t_config_logic set  remark = '%s'  where name = 'Config_sys_info_homepage_msg';",
		EscapeString($prompt_value));
	} 
	else 
	{
		$str_sql = sprintf("insert into t_config_logic(name, remark) values('Config_sys_info_homepage_msg', '%s');",
		EscapeString($prompt_value));
	} 	
	DBHelper::ExecReturnJSON($str_sql);
    //DBHelper::ExecAndPrintMsg($str_sql);
}

//查询首页滚动信息
function HttpAction_SelectConfigSysInfoHomePageMsg() 
{		 
	$str_sql = "select remark from t_config_logic where name = 'Config_sys_info_homepage_msg';"; 
	DBHelper::QueryReturnJSON($str_sql);
}

//----------------------注册-左边滚动信息设置--------------------
function HttpAction_EditConfigSysRegisterSexLeftInfo()
{ 
	$prompt_value = GetRequest("Config_sys_register_sex_left_info");
	$str_sql = sprintf("select * from t_config_logic where name = 'Config_sys_register_sex_left_info';"); 
	
	$bExec = true;
	$msg = "";
	$rsArray = DBHelper::Query($str_sql, $msg);
	if ($rsArray == - 1) 
	{
		PrintMsgToHTML("错误：" . $msg);
		return;
	}

	if (count($rsArray) > 0) 
	{	//存在，则修改 
		$str_sql = sprintf("update t_config_logic set  remark = '%s'  where name = 'Config_sys_register_sex_left_info';",
		EscapeString($prompt_value));
	} 
	else 
	{
		$str_sql = sprintf("insert into t_config_logic(name, remark) values('Config_sys_register_sex_left_info', '%s');",
		EscapeString($prompt_value));
	} 	
	DBHelper::ExecReturnJSON($str_sql);
    //DBHelper::ExecAndPrintMsg($str_sql);
}

//查询注册-左边滚动信息设置
function HttpAction_SelectConfigSysRegisterSexLeftInfo() 
{		 
	$str_sql = "select remark from t_config_logic where name = 'Config_sys_register_sex_left_info';"; 
	DBHelper::QueryReturnJSON($str_sql);
}

?>
